package utils.handlers;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.alibaba.excel.write.handler.CellWriteHandler;
import com.alibaba.excel.write.handler.context.CellWriteHandlerContext;

import utils.style.WishExcelStyle;

public class RowBoldWriteHandler implements CellWriteHandler
{
	private List<Integer> dataIndexs = new ArrayList<>();

	private boolean useRelativeRow = true;

	public RowBoldWriteHandler(List<Integer> dataIndexs)
	{
		this.dataIndexs = dataIndexs;
	}

	public RowBoldWriteHandler(List<Integer> dataIndexs, boolean useRelativeRow)
	{
		this.dataIndexs = dataIndexs;
		this.useRelativeRow = useRelativeRow;
	}

	public RowBoldWriteHandler(Integer dataIndex)
	{
		this.dataIndexs = Arrays.asList(dataIndex);
	}

	public RowBoldWriteHandler(Integer dataIndex, boolean useRelativeRow)
	{
		this.dataIndexs = Arrays.asList(dataIndex);
		this.useRelativeRow = useRelativeRow;
	}

	@Override
	public void afterCellDispose(CellWriteHandlerContext context)
	{
		int index = context.getRelativeRowIndex();
		if (!useRelativeRow)
		{
			index = context.getRowIndex() - context.getHeadData().getHeadNameList().size();
		}
		if (dataIndexs.contains(index))
		{
			context.getFirstCellData().setWriteCellStyle(WishExcelStyle.getWriteCellStyleBold());
		}
	}

}
